package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.Account;
import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.Client;

public class BankService {
    public static void addClient(Bank bank, Client client) {
        bank.addClient(client);
    }

    public static void printBalance(Bank bank) {
        for (Client client : bank.getClients()) {
        	if (client != null) {
        		System.out.println(client.getClientSalutation() + " Balance: "
        				+ client.getAccount().getBalance());
        		if (client.getAccount().getClass().getName() == "com.acme.bankapp.domain.bank.CheckingAccount")
        			System.out.println("       Overdraft: "+client.getAccount().maximumAmountToWithdraw());
        	}
        }
    }

    public void modifyBank(Bank bank){

    	String name2Upd1="Alekseeva A.A.";
    	Account account=getClientAccount(bank,name2Upd1);

    	System.out.print("Transaction for client: "+name2Upd1);
    	account.deposit(777777.77);

    	System.out.print("Transaction for client: "+name2Upd1);
    	account.withdraw(200000);
    	
    	String name2Upd2="Sidorov S.S.";
    	account=getClientAccount(bank,name2Upd2);
    	
    	System.out.print("Transaction for client: "+name2Upd2);
    	account.deposit(100000.00);

    	System.out.print("Transaction for client: "+name2Upd2);
    	account.withdraw(222222.22);
    }

    private Account getClientAccount(Bank bank, String nameCli){
    	Client client=bank.getClient(nameCli);
    	return client.getAccount();
    } 
}
